'use strict';

const Controller = require('egg').Controller;

class NewsController extends Controller {
    async getLoginHistoryCount() {
        const { ctx, service } = this;
        const { userId } = ctx.params;

        try {
            const result = await service.record.getLoginHistoryCountSrv(userId);
            // const date = new Date();
            ctx.successResult({
                ...result,
                // local: `${date.getFullYear()} ${date.getMonth() + 1} ${date.getDate()} ${date.getHours()} ${date.getMinutes()} ${date.getSeconds()}`,
                // utc: `${date.getUTCFullYear()} ${date.getUTCMonth() + 1} ${date.getUTCDate()} ${date.getUTCHours()} ${date.getUTCMinutes()} ${date.getUTCSeconds()}`
            });
        } catch (error) {
            ctx.errorResult(error.message);
        }
    }

    async getLoginLocationRecord() {
        const { ctx, service } = this;

        try {
            const result = await service.record.getLoginLocationRecordSrv();
            ctx.successResult(result);
        } catch (error) {
            ctx.errorResult(error.message);
        }
    }
}

module.exports = NewsController;
